<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <p>1.新增对象属性</p>
    <p v-for="(val, key) in obj1" :key="val">{{key}}-{{val}}</p>
    <button @click="add">add</button>
    <p>2.删除对象属性</p>
    <p v-for="(val, key) in obj1" :key="key">{{key}}-{{val}}</p>
    <button @click="del">del</button>
  </div>
  <script src="../vue.js"></script>
  <script>
    let vm = new Vue({
      el: '#app',
      data: {
        obj1: {
          name: 'Ma baoguo',
          age: 70,
          title: '形意八卦掌门人',
          kongfu: '闪电五连鞭'
        }
      },
      methods: {
        add() {
          // this.obj1.hasWude = '讲武德'; 错误的方法
          this.$set(this.obj1, 'hasWude', '讲武德');
          console.log(this.obj1);
        },
        del() {
          // delete this.obj1.age; 错误的方法
          this.$delete(this.obj1, 'age');
          console.log(this.obj1);
        }
      },
    })
  </script>
</body>
</html>